package service

import (
	userDao "gin/dao"
	user "gin/domain"
	"gin/utils"
)

func Login(name string, pwd string) (bool, user.Tb_user) {
	u1 := userDao.Login(name, pwd)
	if u1.Name == "" && u1.Pwd == "" {
		return false, user.Tb_user{}
	}
	return true, u1
}
func GetUserList() []user.Tb_user {
	return userDao.GetUserList()
}
func Register(user user.Tb_user) bool {
	str := utils.ToMd5(user.Pwd)
	user.Pwd = str
	return userDao.Register(user)
}
func Delete(user user.Tb_user) bool {
	return userDao.Delete(user)
}
func Admin(name string, pwd string) (bool, user.Tb_admin) {
	u1 := userDao.Admin(name, pwd)
	if u1.Name == "" && u1.Pwd == "" {
		return false, user.Tb_admin{}
	}
	return true, u1
}
func Modify(user user.Tb_user, newForm user.Tb_user) (bool, user.Tb_user) {
	flag, user := userDao.Modify(user, newForm)
	return flag, user
}
func AdModify(id int64, newForm user.Tb_user) bool {
	var u user.Tb_user
	u.Id = id
	return userDao.AdModify(u, newForm)
}
